from agno.agent import Agent
from agno.models.deepseek import DeepSeek
from agno.models.ollama import Ollama
from agno.os import AgentOS
from agno.tools.mcp import MCPTools
import os
from dotenv import load_dotenv

# 创建MCP工具连接 - 连接到我们自己的MCP服务器
mcp_tools = MCPTools(
    transport="streamable-http",
    url="http://localhost:8001/mcp"  # 连接到我们自己的MCP服务器
)

# 创建AI助手
assistant = Agent(
    name="My Custom Assistant",
    model=DeepSeek(
        id="deepseek-chat",
        base_url="https://api.deepseek.com",
        api_key="sk-6b841733d8f84db3bfaacf65c5efc6b2"  # 从环境变量读取API密钥
    ),
    # model=Ollama(
    #     id="deepseek-r1:7b",
    #     host="http://192.168.2.10:11434",
    # ),
    markdown=True,
    tools=[mcp_tools],
    description="我是一个自定义的AI助手，可以帮你查询天气、计算数学问题、获取时间和搜索新闻。"
)

# 创建AgentOS实例
agent_os = AgentOS(
    os_id="my-custom-agent",
    description="My Custom AI Agent with Weather, Calculator and News Tools",
    agents=[assistant]
)

# 获取应用实例
app = agent_os.get_app()

if __name__ == "__main__":
    # 在端口7778启动服务，避免与原来的agent冲突
    agent_os.serve(app="my_agent:app", port=7798, reload=True)
